/**
 * 表单验证
 * 
 * @param {Object} rules 验证字段的规则
 * @param {Object} messages 验证字段的提示信息
 * 
 */

import basic from '../model/basic.js';
var actmodel = new basic();
actmodel.do=""
actmodel.setdo=function(vdo){
  actmodel.do=vdo;
}

actmodel.get=function(urlpara){
  var app = getApp(); 
  if(!urlpara["do"]&&actmodel.do){
    urlpara["do"]=actmodel.do
  } 
  
  var that= this;
  return new Promise((resolve, reject) => {
    app.util.request({
      'url': 'entry/wxapp/',
      'data': urlpara,
      'method': "get",
      showLoading: false,
      success: function (res) {
        if (res.data.errno == 0) {                
          resolve(res.data.data);
        }
        reject(res.data.message);
      },
      fail: function (res) {
        reject(((res.data && res.data.message) ? res.data.message : res.errMsg));
      }    
    });
  });
}



actmodel.post=function(urlpara,data){
  var app = getApp(); 

  if(!urlpara["do"]&&actmodel.do){
    urlpara["do"]=actmodel.do
  }  
   var url =app.util.url('entry/wxapp',urlpara)
  var that= this;
  return new Promise((resolve, reject) => {
    app.util.request({
      url,
      'data': data,
      'method': "post",
      showLoading: false,
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
        },
      success: function (res) {
        if (res.data.errno == 0) {                
          resolve(res.data.data);
        }
        reject(res.data.message);
      },
      fail: function (res) {
        reject(((res.data && res.data.message) ? res.data.message : res.errMsg));
      }    
    });
  });
}

 module.exports = actmodel;